﻿using Autofac;
using AutoMapper.Configuration;
using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Extensions.Configuration;

namespace VIP.Domain
{
    public static class APIOptionExtentions
    {
        public static ContainerBuilder LoadAPIConfig(this ContainerBuilder builder, Microsoft.Extensions.Configuration.IConfiguration config)
        {
            var connOpt = config.GetSection(DBConnectionOptions.OptionsSectionName).Get<DBConnectionOptions>();
            builder.Register(ctx => Options.Create(connOpt)).SingleInstance();

            var domainOpt = config.GetSection(DomainOptions.OptionsSectionName).Get<DomainOptions>();
            builder.Register(ctx => Options.Create(domainOpt)).SingleInstance();

            var cacheOpt = config.GetSection(EasycachingOptions.OptionsSectionName).Get<EasycachingOptions>();
            builder.Register(ctx => Options.Create(cacheOpt)).SingleInstance();
                        
            return builder;
        }
    }
}
